﻿using System.ComponentModel;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using TomNet.App.Core.Contracts;
using TomNet.App.Model.DB;
using TomNet.App.Model.DTO;
using TomNet.AspNetCore.Data;
using TomNet.SqlSugarCore.Entity;
using TomNet.App.Model.DB.Identity;

namespace TomNet.App.Web.Controllers
{
    [Authorize]
    [Description("提现订单管理")]
    public class WithdrawCashRunningsController : Controller
    {
        private readonly IWithdrawCashRunningsContract _withdrawCashRunningsContract;        
        private readonly IUnitOfWork _unitOfWork;
        public WithdrawCashRunningsController(IWithdrawCashRunningsContract withdrawCashRunningsContract,            
            IUnitOfWork unitOfWork)
        {
            _withdrawCashRunningsContract = withdrawCashRunningsContract;
            _unitOfWork = unitOfWork;
        }
        [Description("提现订单列表")]
        [HttpGet]
        public IActionResult WithdrawCashRunningsList()
        {
            return View();
        }
        [Description("提现订单列表")]
        [HttpPost]
        public IActionResult WithdrawCashRunningsList(int page = 1, int limit = 20)
        {
            var query = _withdrawCashRunningsContract.UnitOfWork.DbContext.Queryable<WithdrawCashRunnings, Users>((w,u)
                   => w.UserID == u.Id)
                //.Where((ub, b, u) => r.Id == intType)
                .OrderBy((w, u) => w.Id, OrderByType.Desc)
               .Select((w, u) => new WithdrawCashRunningsDto
               {
                   UserName = u.UserName,
                   UserID = u.Id,
                   CreatedTime = w.CreatedTime,
                   Amount = w.Amount,
                   Poundage = w.Poundage,
                   Address = w.Address,
                   PayTime = w.PayTime,
                   PaySuccessTime = w.PaySuccessTime,
                   Txid = w.Txid,
                   State = w.State
               });
            int total = 0;
            var list = query.ToPageList(page, limit, ref total);
            var result = new LayuiPageResult<WithdrawCashRunningsDto>
            {
                Code = 0,
                Msg = "Success",
                Count = total,
                Data = list.ToArray()
            };
            return Json(result);
        }
        //[Description("奖励订单添加")]
        //[HttpGet]
        //public IActionResult UserRewardBusinessInsert()
        //{
        //    return View();
        //}
        //[Description("奖励订单添加")]
        //[HttpPost]
        //public IActionResult UserRewardBusinessInsert(UserRewardBusiness userRewardBusiness)
        //{
        //    AjaxResult result = new AjaxResult { Type = Data.AjaxResultType.Error, Content = "未知异常", Data = null };
        //    var count = _userRewardBusinessContract.Entities.AsQueryable().Where(m => m.BusinessID == userRewardBusiness.BusinessID).Count();
        //    if (count > 0)
        //    {
        //        result.Content = "订单已经存在";
        //    }
        //    else
        //    {
        //        result.Content = "操作成功";
        //        result.Type = Data.AjaxResultType.Success;
        //        _userRewardBusinessContract.Insert(userRewardBusiness);
        //    }

        //    return Json(result);
        //}
        //[Description("奖励订单修改")]
        //[HttpGet]
        //public IActionResult UserRewardBusinessEdit(int id)
        //{
        //    var goods = _userRewardBusinessContract.Entities.AsQueryable().Where(m => m.Id == id).First();
        //    return View(goods);
        //}
        //[Description("奖励订单修改")]
        //[HttpPost]
        //public IActionResult UserRewardBusinessEdit(UserRewardBusiness userRewardBussiness)
        //{
        //    AjaxResult result = new AjaxResult { Type = Data.AjaxResultType.Error, Content = "未知异常", Data = null };
        //    var count = _userRewardBusinessContract.Entities.AsQueryable().Where(m => m.BusinessID == userRewardBussiness.BusinessID && m.Id != userRewardBussiness.Id).Count();
        //    if (count > 0)
        //    {
        //        result.Content = "订单已经存在";
        //    }
        //    else
        //    {
        //        result.Content = "操作成功";
        //        result.Type = Data.AjaxResultType.Success;
        //        _userRewardBusinessContract.Update(userRewardBussiness);
        //    }
        //    return Json(result);
        //}
        //[Description("奖励订单删除")]
        //[HttpPost]
        //public IActionResult UserRewardBusinessDelete(int id)
        //{
        //    AjaxResult result = new AjaxResult { Type = Data.AjaxResultType.Error, Content = "未知异常", Data = null };
        //    int count = _userRewardBusinessContract.Delete(id);
        //    if (count > 0)
        //    {
        //        result.Content = "操作成功";
        //        result.Type = Data.AjaxResultType.Success;
        //    }
        //    else
        //    {
        //        result.Content = "操作失败";
        //        result.Type = Data.AjaxResultType.Error;
        //    }
        //    return Json(result);
        //}
    }
}